﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using Libs.Db;

namespace Libs.HR
{
    public class EmployeeInfo
    {
        public int EmployeeID { get; set; }
        public string PrivateEmail { get; set; }
        public bool Married { get; set; }
        public string HomePhone { get; set; }
        public string CurrentAddress { get; set; }
        public string PermanentAddress { get; set; }
        public string OriginalAddress { get; set; }
        public string IDNumber { get; set; }
        public DateTime IDNumberTime { get; set; }
        public string IDNumberCity { get; set; }
        public int EducationID { get; set; }
        public string Ethnic { get; set; }
        public string Religion { get; set; }
        public string Description { get; set; }
        public int ReturnValue { get; set; }

        public EmployeeInfo()
        {

        }

        ~EmployeeInfo()
        {

        }

        public virtual void Dispose()
        {

        }

        /// <summary>
        /// Lấy giá trị EmployeeInfo theo ID
        /// </summary>
        /// <param name="employeeID"></param>
        /// <returns></returns>
        public EmployeeInfo Get(int employeeID)
        {
            DbHelper db = new DbHelper(Config.HRConnectionStrings);
            return db.GetInstanceSP<EmployeeInfo>("sp_EmployeeInfo_Select",
                new SqlParameter("@EmployeeID", employeeID));
        }

        /// <summary>
        /// Lấy giá trị EmployeeInfo theo ID
        /// </summary>
        /// <returns></returns>
        public EmployeeInfo Get()
        {
            DbHelper db = new DbHelper(Config.HRConnectionStrings);
            return db.GetInstanceSP<EmployeeInfo>("sp_EmployeeInfo_Select",
                new SqlParameter("@EmployeeID", EmployeeID));
        }

        /// <summary>
        /// Thêm mới EmployeeInfo
        /// </summary>
        public void Add()
        {
            DbHelper db = new DbHelper(Config.HRConnectionStrings);
            SqlParameter[] pars = new SqlParameter[14];
            pars[0] = new SqlParameter("@EmployeeID", EmployeeID);
            pars[1] = new SqlParameter("@PrivateEmail", PrivateEmail);
            pars[2] = new SqlParameter("@Married", Married);
            pars[3] = new SqlParameter("@HomePhone", HomePhone);
            pars[4] = new SqlParameter("@CurrentAddress", CurrentAddress);
            pars[5] = new SqlParameter("@PermanentAddress", PermanentAddress);
            pars[6] = new SqlParameter("@OriginalAddress", OriginalAddress);
            pars[7] = new SqlParameter("@IDNumber", IDNumber);
            pars[8] = new SqlParameter("@IDNumberTime", IDNumberTime);
            pars[9] = new SqlParameter("@IDNumberCity", IDNumberCity);
            pars[10] = new SqlParameter("@EducationID", EducationID);
            pars[11] = new SqlParameter("@Ethnic", Ethnic);
            pars[12] = new SqlParameter("@Religion", Religion);
            pars[13] = new SqlParameter("@Description", Description);

            db.ExecuteNonQuerySP("sp_EmployeeInfo_Insert", pars);
        }

        /// <summary>
        /// Cập nhật Contract
        /// </summary>
        public void Update()
        {
            DbHelper db = new DbHelper(Config.HRConnectionStrings);
            SqlParameter[] pars = new SqlParameter[15];
            pars[0] = new SqlParameter("@ReturnValue", SqlDbType.Int) { Direction = ParameterDirection.Output };
            pars[1] = new SqlParameter("@EmployeeID", EmployeeID);
            pars[2] = new SqlParameter("@PrivateEmail", PrivateEmail);
            pars[3] = new SqlParameter("@Married", Married);
            pars[4] = new SqlParameter("@HomePhone", HomePhone);
            pars[5] = new SqlParameter("@CurrentAddress", CurrentAddress);
            pars[6] = new SqlParameter("@PermanentAddress", PermanentAddress);
            pars[7] = new SqlParameter("@OriginalAddress", OriginalAddress);
            pars[8] = new SqlParameter("@IDNumber", IDNumber);
            pars[9] = new SqlParameter("@IDNumberTime", IDNumberTime);
            pars[10] = new SqlParameter("@IDNumberCity", IDNumberCity);
            pars[11] = new SqlParameter("@EducationID", EducationID);
            pars[12] = new SqlParameter("@Ethnic", Ethnic);
            pars[13] = new SqlParameter("@Religion", Religion);
            pars[14] = new SqlParameter("@Description", Description);

            db.ExecuteNonQuerySP("sp_EmployeeInfo_Update", pars);
            ReturnValue = Convert.ToInt32(pars[0].Value);
        }

    }
}
